<?php

/**
 * sfGuardUser form.
 *
 * @package    vtns
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrinePluginFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class sfGuardUserForm extends PluginsfGuardUserForm
{
	public function configure()
	{
		$this->setWidgets(array(
		  'id'               => new sfWidgetFormInputHidden(),
		  'first_name'       => new sfWidgetFormInputText(),
		  'last_name'        => new sfWidgetFormInputText(),
		  'email_address'    => new sfWidgetFormInputText(),
		  'username'         => new sfWidgetFormInputText(),
		  'password'         => new sfWidgetFormInputText(),
		  'is_active'        => new sfWidgetFormInputCheckbox(),
		  'is_super_admin'   => new sfWidgetFormInputCheckbox(),
		  'groups_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup')),
		  'permissions_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission')),
		));
		
		$this->widgetSchema->setLabels(array(
				'first_name'						=> 'Họ',
				'last_name'							=> 'Tên',
				'email_address'						=> 'Địa chỉ email',
				'username'							=> 'Tên đăng nhập',
				'password'							=> 'Mật khẩu',
				'is_active'							=> 'Kích hoạt',
				'is_super_admin'					=> 'Super Admin',
				'groups_list'						=> 'Nhóm',
				'permissions_list'					=> 'Phân quyền'
		));
	
		$this->setValidators(array(
		  'id'               => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
		  'first_name'       => new sfValidatorString(array('max_length' => 255, 'required' => false)),
		  'last_name'        => new sfValidatorString(array('max_length' => 255, 'required' => false)),
		  'email_address'    => new sfValidatorString(array('max_length' => 255)),
		  'username'         => new sfValidatorString(array('max_length' => 128)),
		  'password'         => new sfValidatorString(array('max_length' => 128, 'required' => false)),
		  'is_active'        => new sfValidatorBoolean(array('required' => false)),
		  'is_super_admin'   => new sfValidatorBoolean(array('required' => false)),
		  'groups_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup', 'required' => false)),
		  'permissions_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission', 'required' => false)),
		));
	
		$this->validatorSchema->setPostValidator(
		  new sfValidatorAnd(array(
			new sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => array('email_address'))),
			new sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => array('username'))),
		  ))
		);
	
		$this->widgetSchema->setNameFormat('sf_guard_user[%s]');
	
		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	
		$this->setupInheritance();		
	}
}
